<template>
  <div class="header">
    <div class="header-left">
      中部地区
      <van-icon name="arrow" />
    </div>
    <div class="header-right">
      <van-search v-model="SearchValue" shape="round" placeholder="找医院" />
    </div>
  </div>
  <van-swipe class="my-swipe" style="height: 180px;" :autoplay="3000" indicator-color="white">
    <van-swipe-item v-for="item in homeData.slides" :key="item.id">
      <van-image
      radius="5"
      :src="item.pic_image_url"
      />
    </van-swipe-item>
  </van-swipe>
  <van-row justify="space-around">
    <van-col span="11" v-for="(item, index) in homeData.nav2s" :key="item.id" @click="goOrderTwo(index)">
      <van-image
      radius="5"
      :src="item.pic_image_url"
      />
    </van-col>
  </van-row>
  <van-row @click="goOrder(item)" class="yy-list" justify="space-around" v-for="item in homeData.hospitals" :key="item.id">
    <van-col span="6">
      <van-image style="width: 100px; height: 90px;" :src="item.avatar_url"></van-image>
    </van-col>
    <van-col class="yy" span="15">
      <div class="yy-name">{{ item.name }}</div>
      <div class="yy-type">
        <span>{{ item.rank }}</span>
        &nbsp;
        <span>{{ item.label }}</span>
      </div>
      <div class="yy-text">{{ item.intro }}</div>
    </van-col>
  </van-row>
</template>

<script setup>
import { onMounted, reactive, ref } from 'vue';
import { getIndex } from '../../api';
import { useRouter } from 'vue-router';
const router = useRouter()
//搜索框绑定
const SearchValue = ref()
//首页数据
const homeData = reactive({
  hospitals: [],
  nav2s: [],
  navs: [],
  now: '',
  slides:[]
})
//绑定快速跳转
const goOrderTwo = (index) => {
  console.log(index);
  console.log(homeData.hospitals[index].id);
  router.push(`/createOrder?id=${homeData.hospitals[index].id}`)
}
//点击医院跳转
const goOrder = (data) => {
  router.push(`/createOrder?id=${data.id}`)
}
//页面渲染
onMounted( async () => {
  const { data } = await getIndex()
  Object.assign(homeData, data.data)
})
</script>

<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  margin: 5px;
  line-height: 54px;
  .header-left {
    padding-left: 22px;
    background: url()
      no-repeat left center;
    background-size: 20px;
    font-size: 20px;
    font-weight: bold;
    color: #666666;
  }
}
.my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
  }
  .yy-list {
  padding-bottom: 10px;
  margin: 20px 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04), 0 1px 6px 0 rgba(0, 0, 0, 0.04);
  .yy {
    .yy-name {
      font-size: 20px;
      line-height: 30px;
      font-weight: bold;
    }
    .yy-type {
      font-weight: bold;
      line-height: 25px;
      font-size: 15px;
      color: #0ca7ae;
    }
    .yy-text {
      font-size: 14px;
      color: #999999;
    }
  }
}
</style>
